package com.arges.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * web容器配置类
 */

public class WebConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    /**
     *   加载SpringMvc的配置类，产生SpringMvc容器（本质还是Spring容器）
     */
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    };

    /**
     * 加载Spring的配置类
     * @return
     */
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }


    /**
     * 设置由SpringMvc访问路径
     * @return
     */
    @Override
    protected String[] getServletMappings() {
        // 加载所有请求
        return new String[]{"/"};
    }



    /**
     * Post请求 乱码处理
     * @return
     */
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        return new Filter[]{filter};
    }
}